<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', '1');

ob_start();
session_start();
require_once("config.php");
require_once("resources/api/access_user/access_user_class.php");
if(isset($_SESSION['user']) && isset($_SESSION['pw'])) {
	unset($_SESSION['user']);
	unset($_SESSION['pw']);
}

if(isset($_POST['go'])) {
	$userAccess = new Access_user( DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME );
	if (!$userAccess->connected) {
		$message = 'Not a valid db connection.';
	} else {
		if ($_POST['user'] != '' && $_POST['pass'] != '') {
			$ret = $userAccess->login_user($_POST['user'], $_POST['pass']);
			if($ret == 1){
				header('Location: manager.php');
				exit();
			} else if($ret == 0) {
				header('Location: dataentry.php');
				exit();
			} else {
				$message = 'Invalid User Name / Password ';
			}
		}
	}
}
?>
<html>
<head>
<title><?php print TITLE ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.ibox {
	border: thin solid #060;
	padding: 3px;
}
a:link {
	color: #060;
}
a:visited {
	color: #060;
}
a:hover {
	color: #060;
}
a:active {
	color: #060;
}
.ibox:focus {
	background-color:#A5DC4B;
}
body, td, th {
	font-family: Arial, Helvetica, sans-serif;
}
-->
</style>
</head>
<body onLoad="document.forms[0].user.focus();">
<form name="login" action="<?php print $_SERVER['PHP_SELF']; ?>" method="POST">
  <div style="width: 400px;  margin-left: auto; margin-right: auto;" align="center">
    <!--<label style="font-weight:bold;"><img src="" width="318" height="108" alt=""><br />
</label>
<hr size="1" noshade="noshade"><br> -->
<br>
<br>
<?php print TITLE ?>
<br>
    <div>
      <table width="321" border="0" cellspacing="5" cellpadding="0">
        <tr>
          <td width="124">User Name:</td>
          <td width="261"><input type="text" name="user" class="ibox" id="user" /></td>
        </tr>
        <tr>
          <td>Password:</td>
          <td><input type="password" name="pass" class="ibox" id="pass" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="go" value="Login" /></td>
        </tr>
      </table>
      <br>
<?php
	if($message != '') {
		print "<div class='error'>$message</div>";
	}
?>
    </div>
  </div>
</form>
</body>
</html>